<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<p>This tests verifies access to captured arguments via an optimized-away arguments object.
</p>
<script>
// In-bounds of declared and passed arguments, no activation, before tear-off.
function f0(x) {
    return arguments[0] || function() { return x; };
}

// Out-of-bounds of declared arguments, in-bounds of passed arguments, no activation, before tear-off.
function f1(x) {
    return arguments[1] || function() { return x; };
}

// In-bounds of declared arguments, in-bounds of passed arguments, yes activation, before tear-off.
function f2(x) {
    return function() { return x; } && arguments[0];
}

// Out-of-bounds of declared arguments, in-bounds of passed arguments, yes activation, before tear-off.
function f3(x) {
    return function() { return x; } && arguments[1];
}

// In-bounds of declared and passed arguments, no activation, after tear-off.
function f4(x) {
    return arguments || function() { return x; };
}

// Out-of-bounds of declared arguments, in-bounds of passed arguments, no activation, after tear-off.
function f5(x) {
    return arguments || function() { return x; };
}

// In-bounds of declared arguments, in-bounds of passed arguments, yes activation, after tear-off.
function f6(x) {
    return function() { return x; } && arguments;
}

// Out-of-bounds of declared arguments, in-bounds of passed arguments, yes activation, after tear-off.
function f7(x) {
    return function() { return x; } && arguments;
}

test(() => {
    for (let i = 0; i < 200; ++i) {
        assert_equals(f0(1), 1, "f0(1)");
        assert_equals(f1(2, 3), 3, "f1(2, 3)");
        assert_equals(f2(4), 4, "f2(4)");
        assert_equals(f3(5, 6), 6, "f3(5, 6)");
        assert_equals(f4(7)[0], 7, "f4(7)");
        assert_equals(f5(8, 9)[1], 9, "f5(8, 9)");
        assert_equals(f6(10)[0], 10, "f6(10)");
        assert_equals(f7(11, 12)[1], 12, "f7(11, 12)");
    }
});
</script>
